<?php
basename($_SERVER["PHP_SELF"]) == 'inc.public.php' && exit('Invalid Access!');

require_once("inc.config.php");

$_error_report_code = $vars["debug"]? (E_ALL - E_NOTICE) : 0;
error_reporting($_error_report_code);

session_start();
require_once(M_ROOT."/functions/general_function.php");
require_once(M_ROOT."/functions/common/common.php");
require_once(M_ROOT."/functions/downline/downline_function.php");
require_once(M_ROOT."/functions/forms/forms_function.php");
require_once(M_ROOT."/functions/ad/ad_function.php");
require_once("initialize.php");

initialize();
$vars["this_file"]=$this_file=basename($_SERVER["PHP_SELF"]);
$vars["member_title"]="$vars[title] Member Area";
$db=$vars["db"];
$inputbox_style="class='inputbox' style=\"width:99%;\"";

set_referrer_cookie();

/*##### FORM POST/GET #####*/
if(count($_POST)){$posting=1; $temp=get_post(); $post_a=$temp["post_a"]; $post_s=$temp["post_s"]; $post_d=$temp["post_d"]; $post_h=$temp["post_h"];}
if(count($_GET)){$getting=1; $temp=get_get(); $get_a=$temp["get_a"]; $get_s=$temp["get_s"]; $get_d=$temp["get_d"]; $get_h=$temp["get_h"];}
if(count($_COOKIE)){$temp=get_cookie(); $cookie_a=$temp["cookie_a"]; $cookie_s=$temp["cookie_s"]; $cookie_d=$temp["cookie_d"]; $cookie_h=$temp["cookie_h"];}

function format_public_page($content, $title, $content_title, $head_info="", $keyword="", $gzip=true){
global $vars;
$db=$vars["db"];

//open file
$tpl=file_get_contents(TEMPLATE_PATH. "/". $vars["template"] . "/public.htm");

if(check_user_is_logged()){
$member_menu=
"<p class='bold'>".__("Member Menu")."</p>
&gt; <a href='<%murl_index%>'>".__("Member Home")."</a><br />
&gt; <a href='<%murl_profile%>'>".__("Profile")."</a><br />
&gt; <a href='<%murl_purchase%>'>".__("Purchase")."</a><br />
&gt; <a href='<%murl_genealogy%>'>".__("Genealogy")."</a><br />
&gt; <a href='<%murl_network%>'>".__("Network")."</a><br />
&gt; <a href='<%murl_placement%>'>".__("Placement")."</a><br />
&gt; <a href='<%murl_commission%>'>".__("Commission")."</a><br />
&gt; <a href='<%murl_purchase_history%>'>".__("History")."</a><br />
&gt; <a href='<%murl_support%>'>".__("Support")."</a><br />
&gt; <a href='<%murl_compensation%>'>".__("Compensation Plan")."</a><br />
&gt; <a href='<%murl_logout%>'>".__("Logout")."</a>";
}

/*replace tag
$page=replace_tag($tpl, array(
"<%title%>"=>$title,
"<%charset%>"=>$vars["charset"],
"<%meta_title%>"=>$vars["meta_title"],
"<%meta_desc%>"=>$vars["meta_desc"],
"<%meta_keyw%>"=>$vars["meta_keyw"].($keyword? " $keyword" : ""),
"<%head_info%>"=>$head_info,
"<%template_url%>"=>TEMPLATE_URL . "/$vars[template]",
"<%js_url%>"=>JS_URL,
"<%url_home%>"=>M_URL,
"<%member_menu%>"=>$member_menu,
"<%news%>"=>file_get_contents(M_ROOT.'/'.$vars['file']['public']['news_short']),
"<%content_header%>"=>$content_title,
"<%content%>"=>$content,
"<%menu%>"=>$menu,
"<%copy_year%>"=>intval(ndate('Y'))>2009? '2009 - '.ndate('Y') : ndate('Y')));
*/
$page=replace_tag($tpl, array(
"<%title%>"=>$title,
"<%charset%>"=>$vars["charset"],
"<%meta_title%>"=>$vars["meta_title"],
"<%meta_desc%>"=>$vars["meta_desc"],
"<%meta_keyw%>"=>$vars["meta_keyw"].($keyword? " $keyword" : ""),
"<%head_info%>"=>$head_info,
"<%template_url%>"=>TEMPLATE_URL . "/$vars[template]",
"<%js_url%>"=>JS_URL,
"<%url_home%>"=>M_URL,
"<%member_menu%>"=>$member_menu,
"<%news%>"=>'',
"<%content_header%>"=>$content_title,
"<%content%>"=>$content,
"<%menu%>"=>$menu,
"<%copy_year%>"=>intval(ndate('Y'))>2009? '2009 - '.ndate('Y') : ndate('Y')));

//replace file
foreach($vars["file"]["public"] as $file=>$fname){
 $page=str_replace("<%purl_$file%>", M_URL."/".$fname, $page);
}
foreach($vars["file"]["member"] as $file=>$fname){
 $page=str_replace("<%murl_$file%>", MEMBER_URL."/".$fname, $page);
}


//replace language
//$page=preg_replace('/_%(.+)%_/e', "__('\$1')", $page);
//$page=preg_replace('/<%(.+_title)%>/e', "__(\$vars['\$1'])", $page);

//ad
//$page=format_ad($page);

//compression
if(!headers_sent()){
 header("Content-Type:text/html; charset=$vars[charset]");
 $encodings=array();
 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));

 if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
  $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
 }
}

if($enc && $vars["gzip"] && $gzip && !headers_sent()){
 header("Vary: Accept-Encoding");  // Handle proxies
 header('Content-Encoding: '.$enc);
 header("Expires: " . date("r", time()-10000));
 $page = gzencode($page, 7, FORCE_GZIP);
}

return $page;
}

function set_referrer_cookie(){
 global $vars;
 $db=$vars["db"];
 if($_GET["r"] && @mysql_num_rows(mysql_query("select * from $db->users where id='$_GET[r]'"))){
  setcookie("r", $_GET["r"], ntime()+$vars["referral_cookie_duration"]*86400);
 }
}
?>